/**
 * Created by Richard Radlherr.
 * Date: 24.06.2006 17:26
 */

using System;
using TagTool.Core;
using TagTool.GraphicTypes;

namespace TagTool.Nodes.Math
{

	public class ScaleVector : BaseNode
	{
		private InputSlot slotA;
		private InputSlot slotB;
		private OutputSlot slotC;
  
		public ScaleVector() : base()
		{
			Name = "ScaleVector";
			slotA = new InputSlot(this, "Point", new PointD());
			slotA.ParseCallback = ParseHelper.ParseVector;
			
			slotB = new InputSlot(this, "Factor", 1.0);
			slotB.ParseCallback = ParseHelper.ParseDouble;
			
			slotC = new OutputSlot(this, "Result", typeof(PointD));
			slotC.Value = slotA.Value;
		}

		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot SlotA
		{
			get { return slotA; }
		}

		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot SlotB
		{
			get { return slotB; }
		}

		[NodeAttribute(SlotType.Output, Show = true)]
		public OutputSlot SlotC
		{
			get { return slotC; }
		}

		public override void Update(Object sender)
		{
			slotC.Value = ((PointD)slotA.Value).Multiply((double)slotB.Value);
		}

	}
	
	public class VectorAddition : BaseNode
	{
		private InputSlot slotA;
		private InputSlot slotB;
		private OutputSlot slotC;
  
		public VectorAddition() : base()
		{
			Name = "Vector Addition";
			slotA = new InputSlot(this, "Point A", new PointD());
			slotA.ParseCallback = ParseHelper.ParseVector;
			
			slotB = new InputSlot(this, "Point B", new PointD());
			slotB.ParseCallback = ParseHelper.ParseVector;
			
			slotC = new OutputSlot(this, "Result", typeof(PointD));
			slotC.Value = slotA.Value;
		}

		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot SlotA
		{
			get { return slotA; }
		}

		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot SlotB
		{
			get { return slotB; }
		}

		[NodeAttribute(SlotType.Output, Show = true)]
		public OutputSlot SlotC
		{
			get { return slotC; }
		}

		public override void Update(Object sender)
		{
			slotC.Value = (PointD)slotA.Value + (PointD)slotB.Value;
		}

	}
	
	public class VectorSubtraction : BaseNode
	{
		private InputSlot slotA;
		private InputSlot slotB;
		private OutputSlot slotC;
  
		public VectorSubtraction() : base()
		{
			Name = "Vector Subtraction";
			slotA = new InputSlot(this, "Point A", new PointD());
			slotA.ParseCallback = ParseHelper.ParseVector;
			
			slotB = new InputSlot(this, "Point B", new PointD());
			slotB.ParseCallback = ParseHelper.ParseVector;
			
			slotC = new OutputSlot(this, "Result", typeof(PointD));
			slotC.Value = slotA.Value;
		}

		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot SlotA
		{
			get { return slotA; }
		}

		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot SlotB
		{
			get { return slotB; }
		}

		[NodeAttribute(SlotType.Output, Show = true)]
		public OutputSlot SlotC
		{
			get { return slotC; }
		}

		public override void Update(Object sender)
		{
			slotC.Value = (PointD)slotA.Value - (PointD)slotB.Value;
		}

	}
}
